package com.fau.wm.action.index;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.fau.wm.action.PublicAction;
import com.fau.wm.entity.MedicalAdmin;
import com.fau.wm.entity.MedicalInStock;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 库存管理Action
 * @author kangyj
 * @datetime 2014年8月11日,上午11:10:26
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class InStockAction extends PublicAction implements ModelDriven<MedicalInStock> {

	private static final long serialVersionUID = 7229436424714652399L;
	
	private MedicalInStock inStock = new MedicalInStock();
	
	/**
	 * @desc 查询到达提醒数的药品
	 * @return null
	 * @author liy
	 * @datetime 2014年12月22日,上午10:43:03
	 */
	@Action(value = "in_stock_warn")
	public String medicineUnderWarn(){
		HttpServletResponse response = ServletActionContext.getResponse();
		map = ActionContext.getContext().getParameters();
		this.list = this.baseAllService.getInStockManagerService().findMedicineUnderWarn();
		formatJSON(response, this.list);
		return null;
	}

	/**
	 * @desc 库存列表页面初始化
	 * @return String
	 * @author kangyj
	 * @datetime 2014年8月11日,上午11:12:49
	 */
	@Action(value = "in_stock_init", results = {@Result(name = SUCCESS, location = "in_stock_init.jsp")})
	public String init(){
		return SUCCESS;
	}
	
	/**
	 * @desc 进入查看药品库存变化页面
	 * @return String
	 * @author liy
	 * @datetime 2014年12月19日,下午5:01:58
	 */
	@Action(value = "medicine_num_change", results = {@Result(name = SUCCESS, location = "medicine_num_change.jsp")})
	public String numChange(){
		return SUCCESS;
	}
	
	/**
	 * @desc 查询库存列表
	 * @return null
	 * @author kangyj
	 * @datetime 2014年8月11日,上午11:15:42
	 */
	@Action(value = "in_stock_view")
	public String view(){
		HttpServletResponse response = ServletActionContext.getResponse();
		map = ActionContext.getContext().getParameters();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		inStock.setHospitalId(admin.getEnterpriseId());
		pageBean = this.baseAllService.getInStockManagerService().findInStockByPage(map, inStock);
		map.clear();
		map.put("total", pageBean.getTotalRow());
		map.put("data", pageBean.getResult());
		formatJSON(response, map);
		return null;
	}
	
	
	@Override
	public MedicalInStock getModel() {
		return inStock;
	}
}
